<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
include("include/session.php");
include("include/classes/class.AuctionHandler.php");

if($session->logged_in && isset($_GET['content']) && is_numeric($_GET['content'])) {
	$evencolour = "#e5f1F0";
	$oddcolour = "#f8fbfc";
	
	if ($_GET['content'] == 1) {
		//Auctions won
?>
	<div width="100%">
		<table style="border: collapse 1px; text-align: center;" cellspacing="3" cellpadding="0">
			<tr height="29">
				<th style="background:#000 url(images/tr_back.gif) repeat-x; color:#000;">Produsul</th>
				<th style="background:#000 url(images/tr_back.gif) repeat-x; color:#000;">Data</th>
				<th style="background:#000 url(images/tr_back.gif) repeat-x; color:#000;">Stare</th>
<?php
	$i = 0;
	$result = $auctionDB->getAuctionsWon($session->username);
	foreach($result as $item) {
		$product = $auctionDB->getProductData($item['product_id']);
		$timestamp = date("H:i:s, j/n/Y", $item['timestamp']);
?>
			<tr height="29">
				<td style="background:<? echo ($i%2) ? $evencolour : $oddcolour?>; padding:.5em;border:1px solid #fff; text-align:center;">
					<a href="main.php?page=24&id=<?php echo $item['auction_id']; ?>"><?php echo $product['product_name']; ?></a>
					<?php echo "&nbsp;".($item['base_price'] + $item['offer_increment'] * $auctionDB->getAuctionOfferCount($item['auction_id']))."&nbsp;CREDITS"; ?>
				</td>
				<td style="background:<? echo ($i%2) ? $evencolour : $oddcolour?>; padding:.5em;border:1px solid #fff; text-align:center;"><?php echo $timestamp; ?></td>
				<td style="background:<? echo ($i%2) ? $evencolour : $oddcolour?>; padding:.5em;border:1px solid #fff; text-align:center;"><?php echo $item['state']; ?></td>
			</tr>
<?php
		$i++;
	}
?>
			</tr>
		</table>
	</div>
<?php
	}
	
	if ($_GET['content'] == 2) { 
		//Offers made
?>
	<div width="100%">
		<table style="border: collapse 1px; text-align: center;" cellspacing="3" cellpadding="0">
			<tr height="29">
				<th style="background:#000 url(images/tr_back.gif) repeat-x; color:#000;">Produsul</th>
				<th style="background:#000 url(images/tr_back.gif) repeat-x; color:#000;">Data</th>
			</tr>
<?php	
		$result = $auctionDB->getUserOffers($session->username);
		$i = 0;
		foreach($result as $item) {
			$auction = $auctionDB->getAuctionData($item['auction_id']);
			$product = $auctionDB->getProductData($auction['product_id']);
			$lastoffer = $auctionDB->getAuctionLatestOffer($item['auction_id']);
			$timestamp = date("H:i:s, j/n/Y", $item['timestamp']);
			if(!$auction['closed'] || $lastoffer['username'] == $session->username) {
?>
			<tr height="29">
				<td style="background:<? echo ($i%2) ? $evencolour : $oddcolour?>; padding:.5em;border:1px solid #fff; text-align:center;"><a href="main.php?page=24&id=<?php echo $item['auction_id']; ?>"><?php echo $product['product_name']; ?></a></td>
				<td style="background:<? echo ($i%2) ? $evencolour : $oddcolour?>; padding:.5em;border:1px solid #fff; text-align:center;"><?php echo $timestamp; ?></td>
			</tr>
<?
				$i++;
			}
		}
?>
		</table>
	</div>
<?php
	}
	
	if($_GET['content'] == 3) {
		// Invites
?>
	<div width="100%">
		<h3>Spune-le si prietenilor tai despre <?php echo WEBSITE_NAME; ?>!</h3><br />
		<p>Poti invita pana la <b><?php echo INVITE_COUNT; ?></b> prieteni. Pentru fiecare prieten invitat 
		care <b>se inregistreaza</b> <br /> primesti bonus <b><?php echo INVITE_REWARD; ?></b> credite 
		<b>la uramtoarea incarcare</b>!</p>
	</div>
<?
	}
}
else {
	echo 'Accesul interzis! <br />';
}
?>
